package org.dxy.trigger.listener.route;

import com.google.common.eventbus.Subscribe;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.dxy.domain.event.route.RouteStepAddedEvent;
import org.dxy.infrastructure.persistent.service.RouteViewService;
import org.dxy.trigger.listener.EventListener;
import org.springframework.stereotype.Component;

/**
 * 工艺路线步骤添加事件监听器
 * @author: dxy
 * @createTime: 2025/8/17 11:49
 */
@Slf4j
@Component
@RequiredArgsConstructor
public class RouteStepAddedEventListener implements EventListener<RouteStepAddedEvent> {
    
    private final RouteViewService routeViewService;
    
    @Override
    @Subscribe
    public void onEvent(RouteStepAddedEvent event) {
        try {
            log.info("处理工艺路线步骤添加事件: routeId={}, stepId={}", 
                    event.routeId(), event.stepId());

            // 这里可以更新路由步骤相关的读模型
            // 具体实现可能需要更新路由步骤视图表或其他相关表
            
            log.info("工艺路线步骤添加事件处理完成, routeId={}, stepId={}", 
                    event.routeId(), event.stepId());
        } catch (Exception e) {
            log.error("处理工艺路线步骤添加事件失败", e);
            throw new RuntimeException("处理工艺路线步骤添加事件失败", e);
        }
    }
}